package org.arch_learn.ioc_aop.aop;


import org.arch_learn.flashboot.ConnectionManager;

import java.sql.Connection;
import java.sql.SQLException;

public class TransactionManager {
    private ConnectionManager connectionManager;

    public TransactionManager() {
    }

    public TransactionManager(ConnectionManager connectionManager) {
        this.connectionManager = connectionManager;
    }

    public void beginTransaction() throws SQLException {
        Connection currentConnection = connectionManager.getCurrentConnection();
        currentConnection.setAutoCommit(false);
    }

    public void commit() throws SQLException {
        Connection currentConnection = connectionManager.getCurrentConnection();
        currentConnection.commit();
    }

    public void rollBack() throws SQLException {
        Connection currentConnection = connectionManager.getCurrentConnection();
        currentConnection.rollback();
    }

    public void close() throws SQLException {
        Connection currentConnection = connectionManager.getCurrentConnection();
        currentConnection.close();
    }
}
